#include <stdio.h>
#include <graphics.h>
#include <process.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <dos.h>

void main()
{
	int x,y,x1,y1,x2,y2;
	int R,r,gsize,gsize1;
	int left1,top1,right1,bottom1,left2,top2,right2,bottom2;
	int scrx,scry,gdriver=DETECT,gmode,errorcode;
	double p,i,j;
	void *bitmap,*bitm;

	registerbgidriver(EGAVGA_driver);
	initgraph(&gdriver,&gmode,"");

	errorcode = graphresult();
	if (errorcode != grOk)  /* an error occurred */
	{
		printf("Graphics error: %s\n", grapherrormsg(errorcode));
		printf("Press any key to halt:");
		getch();
		exit(1);             /* return with error code */
	}

	//p=3.1415/180;
	scrx=getmaxx();scry=getmaxy();	//get screen max croode.
	x=scrx/2;y=scry/2;		//get the center croode.
	R=scry/3;r=scry/6;		//get two circle radius
	i=j=0;

	setfillstyle(SOLID_FILL,RED);setcolor(RED);
	fillellipse(x,y,35,35);
	setcolor(WHITE);
	circle(x,y,R);
	gsize=imagesize(x-r-10,y-r-10,x+r+10,y+r+10);	//get bytes of rectangle area
	bitmap=malloc(gsize);

	gsize1=imagesize(x-10,y-10,x+10,y+10);	//another rectangle area
	bitm=malloc(gsize1);
	//draw pictures
	while(!kbhit())
	{
		//a=p*i;
		j=0;
		x1=x+R*cos(i);y1=y-R*sin(i);
		left1=x1-r-10;top1=y1-r-10;right1=x1+r+10;bottom1=y1+r+10;	//get a rectangle area
		getimage(left1,top1,right1,bottom1,bitmap);
		setfillstyle(SOLID_FILL,BLUE);setcolor(BLUE);
		fillellipse(x1,y1,20,20);
		setcolor(WHITE);
		circle(x1,y1,r);

		while(j<6)
		{
			x2=x1+r*cos(j);y2=y1-r*sin(j);		//another rectangle area
			left2=x2-10;top2=y2-10;right2=x2+10;bottom2=y2+10;
			getimage(left2,top2,right2,bottom2,bitm);
			setfillstyle(SOLID_FILL,WHITE);
			fillellipse(x2,y2,10,10);
			delay(150);
			putimage(left2,top2,bitm,COPY_PUT);
			j++;
			//if(j>6) j=0;
		}

		delay(150);
		putimage(left1,top1,bitmap,COPY_PUT);
		i++;
		if(i>6) i=0;
		//if(j>6) j=0;
	}
	free(bitmap);
	free(bitm);
	closegraph();
}


